
from django.db import router
from django.urls import include, path
from .views.Apiviews import ProductApiView
from .views.Gviews import ProductGAPIView, ProductGdetailApiView
from .views.mixins import ProductListMixin, ProductDetailMixin
from .views.GenericMixin import ProductGListMixin
from .views.viewsetVIew import ProductViewset, ProductGenriceViewset, ProductModelViewset, ProductReadOnlyModelViewset
from .views.users import registerUser
# from .views.login import LoginView, GetCSRFTokenView, TokenLoginView

from rest_framework import routers
# 倒入restframework_simplejwt
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
# 自动生成路由 仅限于viewset 使用
# 实例化路由队形
# router = routers.SimpleRouter()

# 配置defalut路由
router = routers.DefaultRouter()

# 注册路由 1.路由的前缀，2.视图集，3.别名
# router.register("viewset", ProductViewset, basename="viewset")
# router.register("Gviewset", ProductGenriceViewset, basename="Gviewset")
router.register("Mviewset", ProductModelViewset, basename="Gviewset")
# router.register("Rviewset", ProductReadOnlyModelViewset, basename="Gviewset")
# print(router.urls)
urlpatterns = [   
    path('products/', ProductApiView.as_view()),
    path("G_products/", ProductGAPIView.as_view()),
    path("G_products/<int:pk>/", ProductGdetailApiView.as_view()),
    path("minxin/", ProductListMixin.as_view()),
    path("minxin/<int:pk>/", ProductDetailMixin.as_view()),
    path("G_minxin/", ProductGListMixin.as_view()),
    
    # ---------------用户路由
    # path('get-csrf-token/', GetCSRFTokenView.as_view()),
    # path('login/', LoginView.as_view()),
    path('token/', TokenObtainPairView.as_view()),
    path("register/", registerUser),
    
    # path('Mviewset/<int:pk>/reviews/', ProductModelViewset.as_view({"get":"review"})),
    # 自动生成的路由
    path("", include(router.urls))
    # --------------------------------
    # path("viewset/", ProductViewset.as_view({"get": "list", "post": "create"})),
    # path("viewset/<int:pk>/", ProductViewset.as_view({'get': "retrieve", 
    #                                                     "put": 'update', 
    #                                                     'patch':'partial_update', 
    #                                                     'delete': 'destory'}
    #                                                     ))
]